#include <stdio.h>
#include <string.h>
#include <arpa/inet.h>
#include "wrap.h"
int main(int argc, char const *argv[])
{
        int fd = Socket(AF_INET,SOCK_DGRAM,0);
        // 绑定 server的ip和端口
        struct sockaddr_in serv;
        memset(&serv,0,sizeof(serv));
        serv.sin_family = AF_INET;
        serv.sin_port = htons(8787);
        serv.sin_addr.s_addr = htonl(INADDR_ANY);
        Bind(fd,(struct sockaddr *)&serv,sizeof(serv));

        //初始化客户端的地址信息
        struct sockaddr_in client;
        memset(&client, 0, sizeof(client));
        client.sin_family = AF_INET;
        client.sin_port = htons(6767); //客户端要绑定的端口
        inet_pton(AF_INET,"10.0.11.235", &client.sin_addr.s_addr);

        // 给服务器开放广播权限
        int flag = 1;
        setsockopt(fd,SOL_SOCKET,SO_BROADCAST,&flag,sizeof(flag));

        //通讯
        char buf[1024] = {0};
        while (1){
                // 一直给客户端发数据
                fgets(buf,sizeof(buf),stdin);
                int ret  = sendto(fd,buf,strlen(buf)+0,0,(struct sockaddr*)&client,sizeof(client));
                if(ret == -1){
                        perr_exit("sendto error");
                }
                printf("server send buf:%s \n", buf);

                //只是发数据不想接收数据，所以不接收数据
        }
        Close(fd);
        return 0;
}
